//
//  DHNewsViewController.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/5/6.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHNewsViewController.h"
#import "DHNewsView.h"
#import "DHCommunityView.h"
#import "DHCommunityPublishController.h"

@interface DHNewsViewController ()

@property (strong, nonatomic) DHNewsView *newsView; //资讯视图
@property (strong, nonatomic) DHCommunityView *communityView; //社区视图

@end

@implementation DHNewsViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
//    [self.newsView loadNewsData];
    [self.communityView loadLatestData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationView setTitleWithArray:@[@"资讯",@"社区"]];
    
    CGFloat space = 0;
    if (iPhoneX) {
        space = 24;
    }
    self.newsView = [[DHNewsView alloc] initWithFrame:CGRectMake(0, self.navigationView.bottom , kScreenWidth, kScreenHeight - self.navigationView.height - self.tabBarController.tabBar.height)];
    [self.newsView loadNewsData];
    [self.view addSubview:self.newsView];
    
    self.communityView = [[DHCommunityView alloc] initWithFrame:CGRectMake(0, self.navigationView.bottom , kScreenWidth, kScreenHeight - self.navigationView.height - self.tabBarController.tabBar.height)];
    [self.view addSubview:self.communityView];
    self.communityView.hidden = YES;
}

- (void)routerEventWithName:(NSString *)eventName userInfo:(NSDictionary *)userInfo{
    if ([eventName isEqualToString:@"zixun_click"]) {
        self.navigationView.zixunButton.titleLabel.font = [UIFont systemFontOfSize:20];
        self.navigationView.shequButton.titleLabel.font = [UIFont systemFontOfSize:15];
        self.newsView.hidden = NO;
        self.navigationView.editButton.hidden = YES;
        self.communityView.hidden = YES;
        [self.newsView loadNewsData];
    }else if ([eventName isEqualToString:@"shequ_click"]){
        self.navigationView.zixunButton.titleLabel.font = [UIFont systemFontOfSize:15];
        self.navigationView.shequButton.titleLabel.font = [UIFont systemFontOfSize:20];
        self.newsView.hidden = YES;
        self.communityView.hidden = NO;
        self.navigationView.editButton.hidden = NO;
        [self.communityView loadLatestData];
    }else if ([eventName isEqualToString:@"community_publish"]){
        DHCommunityPublishController *vc = [[DHCommunityPublishController alloc] init];
        [self presentViewController:vc animated:YES completion:nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
